<?php
namespace Swiftx\Bundle\WeChat\Interfaces\Common;
use Swiftx\Interfaces\Httpd\Response;

/**
 * 接口控制器基类
 */
abstract class AjaxController extends BaseController{

    /**
     * 显示成功结果
     * @param Response $response
     * @param array $data
     * @return bool
     */
    public function successDisplay(Response $response, $data = null):bool {
        $result['error'] = 0;
        if($data != null)
            $result['data'] = $data;
        $response->echo(json_encode($result));
        return true;
    }

    /**
     * 显示错误结果
     * @param Response $response
     * @param string $message
     * @return bool
     */
    public function errorDisplay(Response $response, string $message):bool {
        $result['error'] = 1;
        $result['message'] = $message;
        $response->echo(json_encode($result));
        return true;
    }

}